package van.planifolia.demo;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/10/31 17:34
 */
public class SellTicket {
    public static void main(String[] args) {
        // 首先要有一个售卖实体，继承Runnable接口并且重写run方法
        Sell sell = new Sell();
        // 根据这个售卖实体来启动三个线程，同时卖票，同时操作 ticketNub
        new Thread(sell, "窗口A").start();
        new Thread(sell, "窗口B").start();
        new Thread(sell, "窗口C").start();

    }
}
class Sell implements Runnable {
    //总票数
    int ticketNub = 100;
    // 卖票的业务
    @Override
    public void run() {
        while (true) {
            if (ticketNub > 0) {
                System.out.println(Thread.currentThread().getName() + "卖出一张票，还剩下" + --ticketNub);
            }else {
                break;
            }
        }
    }
}

